package com.lei.videoapp;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.VideoView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lei.tong.mvp.view.BaseActivty;
import com.lei.videoapp.contract.ShipContract;
import com.lei.videoapp.model.ShipModel;
import com.lei.videoapp.presenter.ShipPresenter;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivty<ShipPresenter> implements ShipContract.View {
    private RecyclerView rvVideo;
    private List<VideoBean.DataBeanX.DataBean> list = new ArrayList<>();
    private MyAdapter adapter;
    private ShipPresenter shipPresenter;


    @Override
    protected void onStart() {
        super.onStart();
        shipPresenter.initdata();
    }

    @Override
    public int bindlayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initview() {
        rvVideo = (RecyclerView) findViewById(R.id.rv_video);
        adapter = new MyAdapter(R.layout.item_layout,list);
        rvVideo.setAdapter(adapter);
        rvVideo.setLayoutManager(new LinearLayoutManager(this));
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(final BaseQuickAdapter adapter, View view, final int position) {
                final CheckBox viewById1 = view.findViewById(R.id.cb_pl);
                CheckBox viewById2 = view.findViewById(R.id.cb1_yh);
                CheckBox viewById3 = view.findViewById(R.id.cb2_yh);
                CheckBox viewById5 = view.findViewById(R.id.cb4_yh);

                switch (view.getId()){
                    case R.id.cb_pl:
                        if (viewById1.isChecked()){
                            viewById1.setText((list.get(position).getTopComment().getUgc().getLikeCount())+"");
                        }else {
                            viewById1.setText((list.get(position).getTopComment().getUgc().getLikeCount()-1)+"");
                        }
                        break;
                    case R.id.cb1_yh:
                        if (viewById2.isChecked()){
                            viewById2.setText((list.get(position).getUgc().getLikeCount()+1)+"");
                        }else {
                            viewById2.setText(list.get(position).getUgc().getLikeCount()+"");
                        }
                        break;
                    case R.id.cb2_yh:
                        break;
                    case R.id.cb4_yh:
                        break;
                }
            }
        });
    }

    @Override
    public void inject() {
        shipPresenter = new ShipPresenter(new ShipModel(),this);
    }


    @Override
    public void initdata() {

    }

    @Override
    public void indata(String json) {
        if (json!=null){
            Log.i("xxr", "indata: "+json);
            Type type = new TypeToken<List<VideoBean.DataBeanX.DataBean>>() {
            }.getType();
            List<VideoBean.DataBeanX.DataBean> dataBeanList = new Gson().fromJson(json, type);
            list.addAll(dataBeanList);
            adapter.notifyDataSetChanged();
        }
    }
}
